<?php
/**
 * Created by PhpStorm.
 * User: wangxiaodan
 * Date: 2017/4/18
 * Time: 下午2:36
 */

/**
 * @return array
 * 记录管理员日志
 */
function add_admin_log($data, $request){
    $user = Auth::guard('admin')->user();
    \App\Models\AdminLogs::create([
        'admin_id'  => $user['id'],
        'log_info'  => $data,
        'log_ip'    => $request->ip(),
        'log_time'  => \Carbon\Carbon::now(),
    ]);
}

/**
 * @return array
 * 检查角色是否有权限
 */
function permissionCheck($perm, $role){
    return $role->hasPermission($perm->name)?true:false;
}

/**
 * @return array
 * 检查用户是否有角色
 */
function roleCheck($role, $user){
    return $user->hasRole($role->name)?true:false;
}

function getAllMenu(){
    return	array(
        'teacher' => array('name' => '老师管理', 'icon'=>'fa-user', 'sub_menu' => array(
            'teacher_list' => array('name' => '老师列表', 'url'=>'admin/teacher'),
            'teacher_groups' => array('name' => '老师组', 'url'=>'admin/groups'),
        )),
        'users' => array('name' => '会员管理', 'icon'=>'fa-user', 'sub_menu' => array(
            //'users_list' => array('name' => '会员列表', 'url'=>'admin/users'),
            'children_list' => array('name' => '学员列表', 'url'=>'admin/children'),
        )),
        'classes' => array('name' => '课程管理', 'icon'=>'fa-user', 'sub_menu' => array(
            'class_list' => array('name' => '课表管理', 'url'=>'admin/classes'),
            'course_subject' => array('name' => '课程维护', 'url'=>'admin/subject'),
            'classes_history' => array('name' => '上课历史', 'url'=>'admin/consume/history'),
        )),
        'consume_manage' => array('name' => '消费管理', 'icon'=>'fa-user', 'sub_menu' => array(
            'pre_paid_cards' => array('name' => '储值卡', 'url'=>'admin/cards'),
            'consume' => array('name' => '消费记录', 'url'=>'admin/consumes'),
        )),
        'system' => array('name' => '系统设置', 'icon'=>'fa-gears', 'sub_menu' => array(
            'sys_logs' => array('name' => '系统日志', 'url'=>'admin/logs'),
            'admin_list' => array('name' => '管理员列表', 'url'=>'admin/adminuser'),
            'role_manage' => array('name' => '角色管理', 'url'=>'admin/roles'),
            'perm_manage' => array('name' => '权限管理', 'url'=>'admin/permissions'),
        )),
//        'tools' => array('name' => '插件工具', 'icon'=>'fa-plug', 'sub_menu' => array(
//            array('name' => '数据备份', 'url'=>''),
//            array('name' => '数据还原', 'url'=>''),
//        )),
//        'count' => array('name' => '统计报表', 'icon'=>'fa-signal', 'sub_menu' => array(
//            array('name' => '销售概况', 'url'=>''),
//            array('name' => '销售排行', 'url'=>''),
//            array('name' => '会员排行', 'url'=>''),
//            array('name' => '销售明细', 'url'=>''),
//            array('name' => '会员统计', 'url'=>''),
//            array('name' => '财务统计', 'url'=>''),
//        )),
    );
}